package com.example.controller;

import com.example.common.Result;
import com.example.entity.Comment;
import com.example.service.CommentService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/selectPage")
    public Result selectPage(Comment comment, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize){
        PageInfo pageInfo = commentService.selectPage(comment, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        commentService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/deleteComment/{id}")
    public Result deleteByFilmId(@PathVariable Integer id){
        commentService.deleteByFilmId(id);
        return Result.success();
    }

    @DeleteMapping("/delete-batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        commentService.deleteBatch(ids);
        return Result.success();
    }

    @PostMapping("/add")
    public Result add(@RequestBody Comment comment){
        commentService.add(comment);
        return Result.success();
    }

    // 查询不同评论数量
    @GetMapping("/countComment/{id}")
    public Result countComment(@PathVariable Integer id){
        List<Comment> list = commentService.countComment(id);
        return Result.success(list);
    }
}
